package com.edu.zql;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by User on 2017/9/4.
 */
public class TTT {

    public static void main(String[] args) throws UnsupportedEncodingException, ParseException {

        /*List<String> list = new ArrayList<String>();
        list.add("https://wqsou.jd.com/search/searchn?key=%E8%BF%9E%E8%A1%A3%E8%A3%99&datatype=1&callback=jdSearchResultBkCbAE&page=16&pagesize=10&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&multi_suppliers=yes&area_ids=19,1607,3155&qp_disable=no&fdesc=%E5%B9%BF%E4%B8%9C");
        list.add("https://wqsou.jd.com/search/searchn?key=%E6%89%8B%E6%9C%BA&datatype=1&callback=jdSearchResultBkCbA&page=2&pagesize=10&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&multi_suppliers=yes&area_ids=19,1607,3155&qp_disable=no&fdesc=%E5%B9%BF%E4%B8%9C");
        list.add("https://wqsou.jd.com/search/searchn?key=%E6%A1%94%E7%B2%92%E7%AB%A5%E8%A3%85%E7%94%B7%E7%AB%A5%E5%A4%8F%E8%A3%85%E5%A5%97%E8%A3%852017%E6%96%B0%E6%AC%BE12%E5%B2%81%E5%B0%8F%E5%AD%A9%E8%A1%A3%E6%9C%8D%E4%BC%91%E9%97%B2%E4%B8%83%E5%88%86%E8%A3%A4%E6%9D%A1%E7%BA%B9%E4%B8%A4%E4%BB%B6&sf=11&as=1&version=V18");
        list.add("https://wqsou.jd.com/search/searchn?key=%E6%A1%94%E7%B2%92%E7%AB%A5%E8%A3%85%E7%94%B7%E7%AB%A5%E5%A4%8F%E8%A3%85%E5%A5%97%E8%A3%852017%E6%96%B0%E6%AC%BE12%E5%B2%81%E5%B0%8F%E5%AD%A9%E8%A1%A3%E6%9C%8D%E4%BC%91%E9%97%B2%E4%B8%83%E5%88%86%E8%A3%A4%E6%9D%A1%E7%BA%B9%E4%B8%A4%E4%BB%B6&datatype=1&callback=jdSearchResultBkCbA&page=1&pagesize=10&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&multi_suppliers=yes&area_ids=19,1607,3155&qp_disable=no&fdesc=广东");
        list.add("https://wqsou.jd.com/search/searchn?key=%E6%89%8B%E8%A1%A8&sf=11&as=1&version=V18");
        list.add("https://wqsou.jd.com/search/searchn?key=%E5%84%BF%E7%AB%A5%E7%94%B5%E5%8A%A8%E4%B8%89%E8%BD%AE%E8%BD%A6&datatype=1&callback=jdSearchResultBkCbA&page=12&pagesize=80&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&area_ids=19%2C1607%2C3155&qp_disable=no&fdesc=%E5%B9%BF%E4%B8%9C");
        list.add("https://wqsou.jd.com/search/searchn?key=%E8%BF%9E%E8%A1%A3%E8%A3%99%E6%A3%89%E9%BA%BB&datatype=1&callback=jdSearchResultBkCbA&page=4&pagesize=80&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&area_ids=19%2C1607%2C3155&qp_disable=no&fdesc=%E5%B9%BF%E4%B8%9C");
        list.add("https://wqsou.jd.com/search/searchn?key=%E5%A5%B3%E7%AB%A5%E5%87%89%E9%9E%8B&datatype=1&callback=jdSearchResultBkCbG&page=8&pagesize=10&ext_attr=no&brand_col=no&price_col=no&color_col=no&size_col=no&ext_attr_sort=no&merge_sku=yes&multi_suppliers=yes&area_ids=19,1607,3155&qp_disable=no&fdesc=%E5%B9%BF%E4%B8%9C");

        for (String url : list) {
            String decode = URLDecoder.decode(url, "UTF-8");
            System.out.println(decode);
        }

        Double i = 1.2E10;
        System.out.println();
        int ii = 10;
        a(--ii);


        System.out.println(new Date(1504675089848L));
        System.out.println(new Date(1504675113762L));


        StringBuffer sb = new StringBuffer();
        sb.append("0123456789", 1, 5);
        System.out.println(sb);*/

        String s = "2015-10-26 hellow or";
        Pattern p = Pattern.compile("(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})");

        Matcher matcher = p.matcher(s);
        matcher.find();
        StringBuffer stringBuffer = new StringBuffer();
        matcher.appendReplacement(stringBuffer, "${year}\\\\${month}\\\\${day}");
        matcher.appendTail(stringBuffer);

        System.out.println(stringBuffer);

        Date date = new Date(1505079637404L);
        System.out.println(sdf2.format(date));
        Date date2 = new Date(1505059200000L);
        System.out.println(sdf2.format(date2));
        Date date3 = new Date(1505030400000L);
        System.out.println(sdf2.format(date3));

        System.out.println("========================");
        c();
    }

    static void c() throws ParseException {
        Calendar calendar = Calendar.getInstance();
        //calendar.add(Calendar.HOUR_OF_DAY, -7);
        System.out.println(calendar.getTime());
        testDate(calendar.getTime());
        System.out.println("======================");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sdf2.parse("2017-09-12 00:00:00");
        testDate(parse);


    }

    static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    static void testDate(Date date) throws ParseException {

        System.out.println(sdf2.format(date));

        String format = sdf.format(date);
        System.out.println(format);
        Date parse = sdf.parse(format);
        System.out.println(sdf2.format(parse));
    }

    public static void a(int a) {
        System.out.println(a);
    }
}
